#ifndef FORMREPORTS_H
#define FORMREPORTS_H

#include <QWidget>

#include "dbmscontainer.h"

namespace Ui {
    class FormReports;
}

struct RepSpacesRes
{
    QVariantList mqvl_ap_indices;
    QStringList mqstrl_addr;
    QList<double> mql_t_space;
    QList<double> mql_l_space;
    QList<double> mql_nl_space;
    QDate   mqd_target;
    inline void clear()
    {
        mqvl_ap_indices.clear();
        mqstrl_addr.clear();
        mql_t_space.clear();
        mql_l_space.clear();
        mql_nl_space.clear();
        mqd_target = QDate();
    }
};

struct RepFinanceRes
{
    QDate mqd_target;
    double m_finance_4[4];
    double m_yt_finance_4[4];
    inline void clear()
    {
        m_finance_4[0] = m_finance_4[1] =\
        m_finance_4[2] = m_finance_4[3] =\
        m_yt_finance_4[0] = m_yt_finance_4[1] =\
        m_yt_finance_4[2] = m_yt_finance_4[3] = 0.0;
        mqd_target = QDate();
    }
};

struct RepPrivateSpacesRes
{
    QDate mqd_target_date;
    QStringList mqstrl_addr;
    QList<double> mql_spaces;
    QList<QDate> mql_dates;
    double m_total_space;
    inline void clear()
    {
       mqstrl_addr.clear();
       mql_spaces.clear();
       mql_dates.clear();
       mqd_target_date = QDate();
       m_total_space = 0.0;
    }
};

class FormReports : public QWidget, public DbmsContainer
{
    Q_OBJECT

    RepSpacesRes m_rep_s;
    RepFinanceRes m_rep_f;
    RepPrivateSpacesRes m_rep_p;
public:
    explicit FormReports(QWidget *parent = 0);
    ~FormReports();
protected:
    void resizeEvent(QResizeEvent *pe);
    void showEvent(QShowEvent *pe);
private:
    Ui::FormReports *ui;
    void gen_rep_spaces(QDate qd);
    void compute_finance_at_month(QDate qd, double *p_finance_4);
    void gen_rep_finance(QDate qd);
    void gen_rep_privates(QDate qd);
    void resize_spaces_table();
    void report_spaces();
    void report_pspaces();
    void report_finance();
private slots:
    void show_excel(bool state);
    void spaces_date_changed(QDate qd);
    void finance_date_changed();
    void private_date_changed();
    void export_report();
};

#endif // FORMREPORTS_H
